<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

    <title>最短距离</title>
  </head>
  <body>
        <div class="container">
                <!-- Content here -->
                <div class="form-group">
                        <label for="y_cord">Y坐标:</label>
                        <input type="text" class="form-control" id="y_cord">
                      </div>
                      <div class="form-group">
                        <label for="x_cord">X坐标:</label>
                        <input type="text" class="form-control" id="x_cord">
                      </div> 
                      <button type="submit" class="btn btn-primary" id='cal'>计算</button>
                      <div>结果:<span id='result'>  <span></div>
        </div>
    
    
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

    <script>
            $(document).ready(function(){
                
            $("#cal").click(function(){
                y=parseFloat($('#y_cord').val());
                x=parseFloat($('#x_cord').val());
                //计算直线方程式
                x1=4181119.7271;
                y1=378755.1432;
                x2=4181551.1935;
                y2=379045.1651;
                A=y2-y1;
                B=x1-x2;
                C=x2*y1-x1*y2;
                d=Math.abs(A*x+B*y+C)/Math.sqrt(A*A+B*B);
                // window.alert(d);
                $('#result').html(d);
            });
            });
        </script>
</body>
</html>